<template>
  <div class="app-container">
    <div class="filter-container">
      <div class="rolePage">
        <el-row>
          <el-col :sm="11">
            <el-date-picker
              v-model="date"
              type="date"
              placeholder="选择早会日期"
              format="yyyy-MM-dd"
              value-format="yyyy-MM-dd"
              class="filter-item"
              @change="fetchData()"
            />
          </el-col>
          <el-col :sm="13" style="text-align: left">
            <div class="title">{{ date }}运营部早会简报</div>
          </el-col>
        </el-row>

      </div>
    </div>
    <el-row class="table">
      <el-table
        ref="multipleTable"
        :data="list"
        tooltip-effect="dark"
        border
        style="width: 100%"
        @selection-change="handleSelectionChange"
      >
        <el-table-column prop="workLines" label="线别" show-overflow-tooltip align="center" />
        <el-table-column
          prop="customerName"
          label="客户名称"
          show-overflow-tooltip
          align="center"
        />
        <el-table-column
          prop="productPatterns"
          label="版型"
          show-overflow-tooltip
          align="center"
        />
        <el-table-column
          prop="plannedInputs"
          label="计划投入"
          show-overflow-tooltip
          align="center"
        />
        <el-table-column
          prop="actualInputs"
          label="实际投入"
          show-overflow-tooltip
          align="center"
        />
        <el-table-column
          prop="plannedAchiRates"
          label="计划达成率"
          show-overflow-tooltip
          align="center"
        />
        <el-table-column
          prop="actualInStorage"
          label="实际入库"
          show-overflow-tooltip
          align="center"
        />
        <el-table-column prop="wipProducts" label="WIP" show-overflow-tooltip align="center" />
        <el-table-column prop="goodRates" label="良率" show-overflow-tooltip align="center" />
        <el-table-column prop="workLossRates" label="工损" show-overflow-tooltip align="center" />
        <el-table-column
          prop="originalLossRates"
          label="原损"
          show-overflow-tooltip
          align="center"
        />
        <el-table-column
          prop="chuanReturnRates"
          label="串返"
          show-overflow-tooltip
          align="center"
        />
        <el-table-column
          prop="dieReturnRates"
          label="叠返"
          show-overflow-tooltip
          align="center"
        />
        <!-- <el-table-column prop="remarks" label="重点事项" show-overflow-tooltip align="center">
                    <template slot-scope="{row,$index}">
                        <el-link type="primary" @click="SeeRow(row)">查看</el-link>
                    </template>
</el-table-column> -->
      </el-table>
      <el-row v-show="list.length>0">
        <el-col :sm="24">
          <div class="title" style="margin-top: 20px;text-align: center;width: 100%;">重点事项</div>
        </el-col>
      </el-row>
      <el-row v-for="(item, index) in list" v-show="list.length>0" :key="index" class="table-content">
        <el-col class="has-workLines" :sm="4">{{ item.workLines }}</el-col>
        <el-col :sm="20" class="">
          <el-col :sm="24" class="content">
            1.投入达成：{{ item.inputFinish }}
          </el-col>
          <el-col :sm="24" class="content">
            2.碎片：{{ item.remarkSuiPian }}
          </el-col>
          <el-col :sm="24" class="content">
            3.良率：{{ item.remarkGoodRates }}
          </el-col>
          <el-col :sm="24" class="content">
            4.其他：{{ item.remarkOther }}
          </el-col>
        </el-col>
      </el-row>
    </el-row>
  </div>
</template>
<script>
import './css/index.scss'
import { briefAdd, briefAllItems, queryAllItems } from '@/api/report'
export default {
  data: function() {
    return {
      activeCardName: 'all',
      dialogFormVisible: false,
      dialogStatus: '',
      // 查询
      date: '',
      langtopicTypeData: [],
      textMap: {
        update: '修改',
        create: '添加'
      },
      SeeData: {
        inputFinish: '',
        remarkSuiPian: '',
        remarkGoodRates: '',
        remarkOther: ''
      },
      temp: {
        meetingId: '',
        workLines: '',
        customerName: '',
        productPatterns: '',
        plannedInputs: '',
        actualInputs: '',
        actualInStorage: '',
        wipProducts: '',
        goodRates: '',
        workLossRates: '',
        originalLossRates: '',
        chuanReturnRates: '',
        dieReturnRates: '',
        inputFinish: '',
        remarkSuiPian: '',
        remarkGoodRates: '',
        remarkOther: ''
      },
      rules: {
        meetingId: [{ required: true, message: '早会日期没有选择', trigger: 'change' }],
        workLines: [{ required: true, message: '线别没有填写', trigger: 'blur' }],
        customerName: [{ required: true, message: '没有填写', trigger: 'blur' }],
        productPatterns: [{ required: true, message: '没有填写', trigger: 'blur' }],
        plannedInputs: [{ required: true, message: '没有填写', trigger: 'change' }],
        actualInputs: [{ required: true, message: '没有填写', trigger: 'change' }],
        actualInStorage: [{ required: true, message: '没有填写', trigger: 'blur' }],
        wipProducts: [{ required: true, message: '没有填写', trigger: 'blur' }],
        goodRates: [{ required: true, message: '没有填写', trigger: 'blur' }],
        workLossRates: [{ required: true, message: '没有填写', trigger: 'blur' }],
        originalLossRates: [{ required: true, message: '没有填写', trigger: 'blur' }],
        chuanReturnRates: [{ required: true, message: '没有填写', trigger: 'blur' }],
        dieReturnRates: [{ required: true, message: '没有填写', trigger: 'blur' }],
        inputFinish: [{ required: true, message: '没有填写', trigger: 'blur' }],
        remarkSuiPian: [{ required: true, message: '没有填写', trigger: 'blur' }],
        remarkGoodRates: [{ required: true, message: '没有填写', trigger: 'blur' }],
        remarkOther: [{ required: true, message: '没有填写', trigger: 'blur' }]
      },
      total: 0,
      pageNo: 1,
      pageSize: 10,
      list: [], // 全部数据
      listDataSelected: [] // 选中数据
    }
  },
  created() {
    // 获取数据
    // this.fetchData();
  },
  methods: {
    // 重置数据
    resetTemp() {
      this.temp = {
        meetingId: '',
        workLines: '',
        customerName: '',
        productPatterns: '',
        plannedInputs: '',
        actualInputs: '',
        actualInStorage: '',
        wipProducts: '',
        goodRates: '',
        workLossRates: '',
        originalLossRates: '',
        chuanReturnRates: '',
        dieReturnRates: '',
        inputFinish: '',
        remarkSuiPian: '',
        remarkGoodRates: '',
        remarkOther: ''
      }
    },
    // 计算计划达成率
    handleInputChange() {
      console.log('temp', this.temp)
      if (this.temp.plannedInputs && this.temp.actualInputs) {
        this.temp.plannedAchiRates = ((this.temp.actualInputs / this.temp.plannedInputs) * 100).toFixed(2) + '%'
        this.$forceUpdate()
      }
    },
    // 打开添加早会弹窗
    handleCreate() {
      this.resetTemp()
      this.dialogStatus = 'create'
      this.dialogFormVisible = true
      this.$nextTick(() => {
        this.$refs['dataForm'].clearValidate()
      })
    },
    //  修改早会
    handleUpdate(row) {
      const data = Object.assign({}, row)
      this.temp = {
        meetingId: data.meetingId,
        workLines: data.workLines,
        customerName: data.customerName,
        productPatterns: data.productPatterns,
        plannedAchiRates: data.plannedAchiRates,
        plannedInputs: data.plannedInputs,
        actualInputs: data.actualInputs,
        actualInStorage: data.actualInStorage,
        wipProducts: data.wipProducts,
        goodRates: data.goodRates,
        workLossRates: data.workLossRates,
        originalLossRates: data.originalLossRates,
        chuanReturnRates: data.chuanReturnRates,
        dieReturnRates: data.dieReturnRates,
        inputFinish: data.inputFinish,
        remarkSuiPian: data.remarkSuiPian,
        remarkGoodRates: data.remarkGoodRates,
        remarkOther: data.remarkOther
      }
      console.log('temp', this.temp)
      this.dialogStatus = 'update'
      this.dialogFormVisible = true
      this.$nextTick(() => {
        this.$refs['dataForm'].clearValidate()
      })
    },
    // 添加早会提交数据
    createData() {
      this.$refs['dataForm'].validate(async(valid) => {
        if (valid) {
          const data = {
            meetingId: this.temp.meetingId,
            workLines: this.temp.workLines,
            customerName: this.temp.customerName,
            productPatterns: this.temp.productPatterns,
            plannedAchiRates: this.temp.plannedAchiRates,
            plannedInputs: this.temp.plannedInputs,
            actualInputs: this.temp.actualInputs,
            actualInStorage: this.temp.actualInStorage,
            wipProducts: this.temp.wipProducts,
            // %
            goodRates: this.temp.goodRates + '%',
            workLossRates: this.temp.workLossRates + '%',
            originalLossRates: this.temp.originalLossRates + '%',
            chuanReturnRates: this.temp.chuanReturnRates + '%',
            dieReturnRates: this.temp.dieReturnRates + '%',

            inputFinish: this.temp.inputFinish,
            remarkSuiPian: this.temp.remarkSuiPian,
            remarkGoodRates: this.temp.remarkGoodRates,
            remarkOther: this.temp.remarkOther
          }
          await briefAdd(data).then((r) => {
            console.log('temp', this.temp)
            this.dialogFormVisible = false
            if (r && r.code == 200) {
              this.$message({
                type: 'success',
                message: r.message
              })
              this.fetchData()
            } else {
              this.$message({
                type: 'error',
                message: r.message
              })
            }
          })
        }
      })
    },
    // 修改早会提交数据
    updateData() {
      this.$refs['dataForm'].validate((valid) => {
        if (valid) {
          const tempData = Object.assign({}, this.temp)
          tempData.timestamp = +new Date(tempData.timestamp) // change Thu Nov 30 2017 16:41:05 GMT+0800 (CST) to 1512031311464
          // updateArticle(tempData).then(() => {
          const index = this.list.findIndex(v => v.id === this.temp.id)
          this.list.splice(index, 1, this.temp)
          this.dialogFormVisible = false
          this.$notify({
            title: 'Success',
            message: 'Update Successfully',
            type: 'success',
            duration: 2000
          })
          // })
        }
      })
    },
    // 删除早会
    handleDelete(row, index) {
      this.$notify({
        title: 'Success',
        message: 'Delete Successfully',
        type: 'success',
        duration: 2000
      })
      this.list.splice(index, 1)
    },
    // 分页组件
    pageSizeChange(newSize) {
      this.pageSize = newSize
      this.pageNo = 1
      this.fetchData()
    },
    delRole(data) {
      this.$confirm('此操作将永久删除账户, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(async() => {
          console.log('data', data)
          const r = await deleteUser({ userId: data.userId })
          if (r && r.code == 200) {
            this.$message({
              type: 'success',
              message: r.message
            })
            this.fetchData()
          } else {
            this.$message({
              type: 'error',
              message: r.message
            })
          }
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          })
        })
    },
    async fetchData(pageNo) {
      if (pageNo) {
        this.pageNo = pageNo
      }
      const params = {
        pageNum: this.pageNo,
        pageSize: this.pageSize,

        singleTime: ''
      }
      if (this.date) {
        params.singleTime = this.date
      }
      const data = await briefAllItems(params)
      this.list = data.data.content
      this.total = data.data.totalSize
    },
    // 表格多选
    handleSelectionChange(val) {
      this.listDataSelected.splice(0)
      val.forEach(e => {
        this.listDataSelected.push(e)
      })
    },
    getTime(time) {
      var date = new Date(time)
      var y = date.getFullYear()
      var m = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1)
      var d = (date.getDate() < 10 ? '0' + (date.getDate()) : date.getDate())
      return y + '-' + m + '-' + d
    }
  }
}
</script>
<style lang="scss" scoped>
.userlist {
    margin-right: 10px;
}

.title {
    height: 20px;
    padding-left: 5px;
    line-height: 20px;
    font-size: 20px;
    font-weight: bold;
    margin-bottom: 23px;
    display: inline-block;
}

.table-content {
    border: 1px solid #dfe6ec;
    border-bottom: none;
}

.table-content:last-child {
    border-bottom: 1px solid #dfe6ec;
}

.has-workLines {
    border-right: 1px solid #dfe6ec;
    height: 177px;
    line-height: 170px;
    text-align: center;
    padding: 10px 0;
    font-size: 20px;
}

.content {
    height: 44px;
    line-height: 23px;
    padding: 10px 10px;
    border-bottom: 1px solid #dfe6ec;
}

.content:last-child {
    border-bottom: none;
}
</style>
